#include "stdafx.h"

void ustrncpy(char* p1, const char* p2, int nChars)
{
  memset(p1, 0, nChars);
  strncpy(p1, p2, nChars);
}

void ustrncpy(char* lpa, const wchar_t* lpw, int nChars)
{
  memset(lpa, 0, nChars);
  WideCharToMultiByte(GetACP(), 0, lpw, -1, lpa, nChars, NULL, NULL);
}

void ustrncpy(wchar_t* p1, const wchar_t* p2, int nChars)
{
  memset(p1, 0, nChars * sizeof(wchar_t));
  wcsncpy(p1, p2, nChars);
}

void ustrncpy(wchar_t* lpw, const char* lpa, int nChars)
{
  memset(lpw, 0, nChars * sizeof(wchar_t));
  MultiByteToWideChar(GetACP(), 0, lpa, -1, lpw, nChars);
}

CString GetWin32ErrorString(DWORD nError)
{
	CString sError;
	if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, nError, 0, sError.GetBuffer(MAX_PATH), MAX_PATH, 0)==0)
	{
		sError.ReleaseBuffer();
		sError.Format(_T("Win32 error code = %d."),nError);
		return sError;
	}
	sError.ReleaseBuffer();
	sError.TrimRight(_T("\r\n"));

	return sError;
}
